<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<% String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title></title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div>
        <form id="ligerForm" action="">
            <div class="fieldset1 tabel_col clearFix">
                <div class="caption">
                    <span class="title">项目信息</span>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">客户</div>
                    <div class="field">
                        <span id="cstNm" name="cstNm">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">合同号</div>
                    <div class="field">
                        <span id="cntNo" name="cntNo">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">支付表号</div>
                    <div class="field">
                        <span id="paySchNo" name="paySchNo">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">项目类型</div>
                    <div class="field">
                        <span id="prjTypCdNm" name="prjTypCdNm">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">客户经理</div>
                    <div class="field">
                        <span id="cstMgrNm" name="cstMgrNm">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">所属事业部</div>
                    <div class="field">
                        <span id="buOrgCdNm" name="buOrgCdNm">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">挂靠公司</div>
                    <div class="field">
                        <span id="lnkCompNm" name="lnkCompNm">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">供应商</div>
                    <div class="field">
                        <span id="splNm" name="splNm">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">担保人</div>
                    <div class="field">
                        <span id="guarNm" name="guarNm">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">产品名称</div>
                    <div class="field">
                        <span id="prdNm" name="prdNm">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">诉讼状态</div>
                    <div class="field">
                        <span id="sueStsCdNm" name="sueStsCdNm">&nbsp;</span>
                    </div>
                </div>
                <div class="caption">
                    <span class="title">黑名单信息</span>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">客户</div>
                    <div class="field">
                        <span id="cstBlkList" name="cstBlkList">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">担保人</div>
                    <div class="field">
                        <span id="guarBlkList" name="guarBlkList">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">供应商</div>
                    <div class="field">
                        <span id="splBlkList" name="splBlkList">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">挂靠公司</div>
                    <div class="field">
                        <span id="lnkCompBlkList" name="lnkCompBlkList">&nbsp;</span>
                    </div>
                </div>
                <div class="caption">
                    <span class="title">核销信息</span>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">逾期租金</div>
                    <div class="field">
                        <span id="ovdRent" name="ovdRent">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">逾期本金</div>
                    <div class="field">
                        <span id="ovdCap" name="ovdCap">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">逾期利息</div>
                    <div class="field">
                        <span id="ovdItr" name="ovdItr">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">逾期罚息</div>
                    <div class="field">
                        <span id="ovdPntItr" name="ovdPntItr">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">逾期天数</div>
                    <div class="field">
                        <span id="ovdDay" name="ovdDay">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">核销时间</div>
                    <div class="field">
                        <span id="vfTm" name="vfTm">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">核销状态</div>
                    <div class="field">
                        <span id="vfStsCdNm" name="vfStsCdNm">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">核销原因</div>
                    <div class="field">
                        <span id="vfReason" name="vfReason">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">核销金额</div>
                    <div class="field">
                        <span id="vfAmt" name="vfAmt">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">后续处理方式</div>
                    <div class="field">
                        <span id="vfHdlWay" name="vfHdlWay">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">违约金</div>
                    <div class="field">
                        <span id="breakAmt" name="breakAmt">&nbsp;</span>
                    </div>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="sqPanel">
                    <div class="sqPanel_head">
                        <span>回款信息</span>
                        <div class="clearFix"></div>
                        <div class="btnsBox posL">
                            <c:if test="${detail == null}">
                            <span id="addRow" class="sq-button sq-button-round" onclick="appendRow();"
                                  class="sq-button sq-button-round">新增</span>
                                <span id="addBtn" class="sq-button sq-button-round" onclick="saveRtnInfo();"
                                      class="sq-button sq-button-round">保存</span>
                            </c:if>
                        </div>
                    </div>
                    <div class="sqPanel_body">
                        <div id="rtnGird" class="sq-grid"></div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">

    var rtnGird = null;
    var detail = '${detail}';
    var infoId = '${infoId}';
    var isAllRtn = ${isAllRtn};

    $(function () {
        $("#ligerForm").ligerForm({
            validate: true
        });
        initGrid();
        initData();
    });

    function initData() {
        $.ajax({
            type: 'get',
            dataType: 'json',
            url: '<%=path%>/ass/assvfinfo/initVfDetailData.do?infoId=' + infoId,
            success: function (msg) {
                if (msg.success == 0) {
                    top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                } else {
                    setAssVfData(msg.data);
                }
            }
        });
    }

    function setAssVfData(data) {
        // 项目信息
        $("#cstNm").html(data.cstNm);
        $("#cntNo").html(data.cntNo);
        $("#paySchNo").html(data.paySchNo);
        $("#prjTypCdNm").html(data.prjTypCdNm);
        $("#cstMgrNm").html(data.cstMgrNm);
        $("#buOrgCdNm").html(data.buOrgNm);
        $("#lnkCompNm").html(data.lnkCompNm);
        $("#splNm").html(data.splNm);
        $("#guarNm").html(data.guarNm);
        $("#prdNm").html(data.prdNm);
        $("#sueStsCdNm").html(data.sueStsCdNm);
        // 黑名单信息
        $("#cstBlkList").html(data.cstBlkList);
        $("#guarBlkList").html(data.guarBlkList);
        $("#splBlkList").html(data.splBlkList);
        $("#lnkCompBlkList").html(data.lnkCompBlkList);
        // 核销信息
        $("#ovdRent").html("￥" + FormatMoney(data.ovdRent / 100));
        $("#ovdCap").html("￥" + FormatMoney((data.ovdRent - data.ovdItr) / 100));
        $("#ovdItr").html("￥" + FormatMoney(data.ovdItr / 100));
        $("#ovdPntItr").html("￥" + FormatMoney(data.ovdPntItr / 100));
        $("#ovdDay").html(data.ovdDay);
        $("#vfTm").html(renderDate("", "", data.crtTm));
        $("#vfStsCdNm").html(data.vfStsCdNm);
        $("#vfReason").html(data.vfSeason);
        $("#vfAmt").html("￥" + FormatMoney(data.vfAmt / 100));
        $("#vfHdlWay").html(data.vfHdlWay);
        $("#breakAmt").html("￥" + FormatMoney(data.breakAmt / 100));
    }

    // 初始化资产核销详情信息
    function initGrid() {
        rtnGird = $("#rtnGird").ligerGrid({
            parms: {"infoId": infoId},
            url: '<%=path%>/ass/assvfinfo/searchRtnLogByInfoId.do',
            method: 'get',
            columns: [
                {
                    display: '回款金额', name: 'rtnAmtYuan', width: 250, enabledSort: true, editor: {type: 'text'},
                    render: function (rowdata, rowindex, value) {
                        if (rowdata.rtnAmtYuan) {
                            return FormatMoney(rowdata.rtnAmtYuan);
                        } else {
                            return null;
                        }
                    }
                },
                {
                    display: '资金编号', name: 'vfFundNo', width: 300, enabledSort: true, editor: {type: 'text'}
                },
                {
                    display: '是否全部回款',
                    name: 'isAllRtn',
                    width: 250,
                    enabledSort: true,
                    editor: {
                        type: 'select',
                        data: isAllRtn,
                        valueField: 'key',
                        textField: 'value'
                    },
                    valueField: 'isAllRtnCd',
                    textField: 'isAllRtnNm',
                    render: function (item) {
                        return item.isAllRtnNm;
                    }
                },
                {
                    display: '回款时间',
                    name: 'rtnTm',
                    width: 250,
                    enabledSort: true,
                    editor: {type: 'date'},
                    render: renderDate
                },
                {
                    display: '操作',
                    isSort: false,
                    width: 150,
                    render: function (rowdata, rowindex, value) {
                        if (!detail) {
                            var h = '<a class="sq-button-hasicon" href="javascript:removeRow(';
                            h += "'" + rowdata.id + "'";
                            h += ')"><i class="sqBtnIco_3"></i>删除</a>'
                            return h;
                        }
                    }
                }
            ],
            enabledEdit: true,
            usePager: false,//是否有分页便签
            root: 'rows',
            record: 'total',
            hideLoadButton: false,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            isScroll: false,//是否有滚动条
            checkbox: false,//列表是否有选择框
            rownumbers: false//列表是否有行号
        });
    }

    function appendRow() {
        var manager = $("#rtnGird").ligerGetGridManager();
        manager.addRow({
            rtnAmt: '',
            fundNo: '',
            isAllRtnCd: '',
            rtnTm: ''
        });
    }

    //保存所选项目联系人信息
    function saveRtnInfo() {
        var girdData = rtnGird.getData();
        if (girdData.length < 1) {
            $.ligerDialog.SQalert({content: "请维护回款信息！", SQ_type: "warning"});
            return false;
        }
        var params = {};
        params.rtnList = JSON.stringify(girdData);
        params.infoId = infoId;
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: params,
            url: '<%=path%>/ass/assvfinfo/saveRtnLogs.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    rtnGird.reload();
                } else {
                    top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    //删除所选项目客户信息
    function removeRow(id) {
        var _ids = [];
        $.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
            if (flag == false) return;
            if (id && id != "undefined") {
                _ids.push(id);
            } else {
                var manager = $("#rtnGird").ligerGetGridManager();
                manager.deleteSelectedRow();
                return;
            }
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {ids: JSON.stringify(_ids)},
                url: '<%=path%>/ass/assvfinfo/removeRtnLogByIds.do',
                success: function (msg) {
                    if (msg.success == 1) {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        rtnGird.reload();
                    } else {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }


    // 格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value && value != '') {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

</script>
</body>
</html>